
/*
 * Question: Try to propose a recursive algorithm
 * to calculate the number of leaf of a binary tree.
 */

#include <iostream>
#include "bitree.h"
using namespace std;

class bitree : public _bitree<bitree, char>
{
};

int leaf_num(bitree *rt)
{
    if (!rt)
        return 0;
    if (!rt->lchild && !rt->rchild)
        return 1;
    return leaf_num(rt->lchild) + leaf_num(rt->rchild);
 }

int main()
{
    bitree * rt;

    bitree_create<bitree, char>(rt, "ex42.txt");
    cout << leaf_num(rt) << endl;
    bitree_destory(rt);

    return 0;
}
